﻿using Bll;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebPages.AdminPages
{
    public partial class Identify : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Databind();
                Repeater1.Visible = true;
            }
        }
        protected void Databind()
        {
            BllLayer bll = new BllLayer();
            List<User_info> list = bll.GetUserInfos();
            List<User_info> data = new List<User_info>();
            List<User_info> data2 = new List<User_info>();
            foreach (User_info i in list)
            {
                if (i.is_accepted == 0)
                {
                    data.Add(i);
                }
                else
                {
                    data2.Add(i);
                }
            }
            Repeater1.DataSource = data;
            Repeater1.DataBind();
        }

        protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            BllLayer bll = new BllLayer();
            if (e.CommandName == "Accept")
            {
                if (bll.UserIdentify(1, bll.GetUserInfo(e.CommandArgument.ToString())) == 1)
                {
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "onekey", "alert('操作成功')", true);
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "onekey", "alert('操作失败')", true);
                }
            }else if (e.CommandName == "Refuse")
            {
                if (bll.UserIdentify(0, bll.GetUserInfo(e.CommandArgument.ToString())) == 1)
                {
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "onekey", "alert('操作成功')", true);
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "onekey", "alert('操作失败')", true);
                }
            }
            Databind();
        }

    }
}